package com.example.lx5_22.message

import androidx.paging.PagingSource
import androidx.paging.PagingState
import com.example.base.entity.MessageEntityItem
import com.example.base.net.ApiService

class MessagePagingSource(apiService: ApiService) : PagingSource<Int,MessageEntityItem>() {
    lateinit var apiService: ApiService
    init {
        this.apiService=apiService
    }

    override fun getRefreshKey(state: PagingState<Int, MessageEntityItem>): Int? {
        return null
    }

    override suspend fun load(params: LoadParams<Int>): LoadResult<Int, MessageEntityItem> {
        try {
            val currentPage = params.key ?:111122223333
            val message = apiService.getMessage("${currentPage}",1)
            return LoadResult.Page(message.data,null, null)
        }catch (e:Exception){
            return LoadResult.Error(e)
        }
    }


}